<?php

class Cat_ArgsParser_Common implements Cat_ArgsParser_Interface
{
	function parse( $string )
	{
		if( !is_numeric( $string ) )
		{
			$res = json_decode( $string, 1 );
		
			if( $res !== null )
			{
				return $res;
			}
		}

		$res = preg_split('/;(\s|$)/', $string);
		$ret = array();

		foreach( $res as $key => $val )
		{
			if ( trim( $val ) == '' )
			{
				continue;
			}

			$pos = mb_strpos($val, '=');

			if ( $pos === false )
			{
				$val = '=' . $val;
				$pos = 0;
			}

			$k = trim(mb_substr($val, 0, $pos));
			$v = trim(mb_substr($val, $pos + 1));

			if ( $k == '' )
			{
				$ret[] = $v;
			}
			else
			{
				$ret[$k] = $v;
			}

		}
		
		return $ret;
	}
}

?>